package com.elephant.core.validation;

import com.elephant.core.utils.ValidatorResult;
import com.elephant.core.utils.ValidatorUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: hai
 * @Date: 2019/1/10 11:15
 */
@RestController
@RequestMapping("/validation")
public class ValidationController {

    @RequestMapping(method = RequestMethod.POST)
    public String check(@RequestBody Person person){

        ValidatorResult validatorResult = ValidatorUtils.validateResult(person);
        if(!validatorResult.isAccess()){
            return validatorResult.getMessage();
        }

        return "success";
    }
}
